export class Storage {
	storage: globalThis.Storage
	constructor(storage: globalThis.Storage) {
		this.storage = storage
	}
	clear() {
		this.storage.clear()
	}
	setItem(key: string, value: any) {
		// 分类处理
		if (typeof value === 'string') {
			this.storage.setItem(key, value)
		} else if (typeof value === 'bigint' || typeof value === 'boolean' || typeof value === 'number' || typeof value === "function") {
			this.storage.setItem(key, value.toString())
		} else {
			this.storage.setItem(key, JSON.stringify(value))
		}
	}
	getItem(key: string) {
		const value = localStorage.getItem(key)
		if (value) {
			try {
				return JSON.parse(value)
			}
			catch {
				return value
			}

		} else {
			return value
		}
	}
	removeItem(key: string) {
		this.storage.removeItem(key)
	}
}
